package com.test.websample.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Util {
    public static String getMD5Hash(String input) {
        try {
            // 创建 MD5 摘要
            MessageDigest md = MessageDigest.getInstance("MD5");

            // 计算 MD5 值
            byte[] messageDigest = md.digest(input.getBytes());

            // 将字节数组转换为十六进制字符串
            StringBuilder sb = new StringBuilder();
            for (byte b : messageDigest) {
                sb.append(String.format("%02x", b));
            }

            return sb.toString();

        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
}
